/**
 * 文件：EditTextBox.java
 * 包名：com.ronri.list.editview.controls;   --- 正式发布时需要修正
 * 说明：文本编辑控件
 * 作者：MS During
 * 日期：2017/4/14
 * 历史：
 */
package com.ronri.list.editview.controls;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

import com.ronri.iflytek.OnSpeechListening;
import com.ronri.iflytek.VoiceInput;
import com.ronri.mapapi.location.service.LocationManager;

//import com.baidu.mapapi.location.service.LocationManager;

// 文本编辑控件
public abstract class EditTextBox extends BaseControl {

    private View mView = null;

    /***
     * 构造函数
     */
    public EditTextBox() {
        super();
        this.ControlName = "EditTextBox";
    }

    /***
     * 加载控件
     * @return
     */
    @Override
    public boolean LoadEditControl() {
        return false;
    }

    /***
     * 显示控件
     * @return
     */
    @Override
    public boolean ShowEditControl(View Anchor) {
        return false;
    }

    /***
     * 隐藏控件
     * @return
     */
    @Override
    public boolean HideEditControl() {
        return false;
    }

    /***
     * 绑定编辑视图
     * @param view
     */
    public void bindEditView(View view)
    {
        mView = view;
    }
    /***
     * 获取语音信息
     * @return
     */
    public void getVoiceText(){
        VoiceInput.getVoiceText(getContext(), new OnSpeechListening() {
            @Override
            public void OnSpeechResult(String szContent) {
                Message locMsg = messageHander.obtainMessage();

                Bundle bundle = new Bundle();
                bundle.putString("Result", szContent);
                locMsg.setData(bundle);
                messageHander.sendMessage(locMsg);
            }
        });
    }

    /****
     * 获取当前坐标位置的地址信息
     */
    public void getLoacteAddressText(){
        // 获取地址
        LocationManager.getLocationInfo(new LocationManager.OnLocationEvent(){
            @Override
            public void OnLocationResult(double lat, double lng, String szAddress) {
                Message locMsg = messageHander.obtainMessage();

                Bundle bundle = new Bundle();
                bundle.putString("Result", szAddress);
                locMsg.setData(bundle);
                messageHander.sendMessage(locMsg);
            }
        });
    }

    /***
     * 回调结果
     * @param szString
     */
    public void CallBackResult(String szString) {

    }

    /***
     * 接收回调数据
     */
    private Handler messageHander = new Handler() {

        // 接收来自定位的消息
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);
            try {
                String szResult = msg.getData().getString("Result");
                CallBackResult(szResult);
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    };

}
